#include "tcl_mtk_atv_tv.h"

TCL_MTK_ATV_TV::TCL_MTK_ATV_TV()
{}

int TCL_MTK_ATV_TV::Read_Data(QDataStream &in)
{
  in>>ui4_ch_val
    >>ps_name
    >>ui4_class
    >>ui4_isfav
    >>ui4_isskip;
  //qDebug("频道号：%d,频率:%d,制式:%d,是否空台标识:%d",ui4_ch_val,ui4_freq,ui4_tv_sys,ui4_nw_flag);
    return 0;
}

int TCL_MTK_ATV_TV::Write_Data(QDataStream &out)
{
  out<<ui4_ch_val
     <<ps_name
     <<ui4_class
     <<ui4_isfav
     <<ui4_isskip;
  //qDebug("频道号：%d,频率:%d,制式:%d,是否空台标识:%d",ui4_ch_val,ui4_freq,ui4_tv_sys,ui4_nw_flag);
    return 0;
}


void TCL_MTK_ATV_TV::Set_Data(int order,QVariant value)
{
    bool *ok=false;
     switch(order)
     {
     case 0:
      ui4_ch_val=value.toUInt(ok);
      Q_ASSERT(*ok==true);
      break;
     case 1:
      ps_name=value.toString();
      break;
     case 2:
      ui4_class=value.toUInt(ok);
      Q_ASSERT(*ok==true);
      break;
     case 3:
      ui4_isfav=value.toUInt(ok);
      Q_ASSERT(*ok==true);
      break;
     case 4:
      ui4_isskip=value.toUInt(ok);
            Q_ASSERT(*ok==true);
      break;
     default:
     // qDebug("In Mtk ATV setData:order error!\n");
         Q_ASSERT(order<5&&order>0);
     }
 }

void TCL_MTK_ATV_TV::Get_Data(QString &ch_val, QString &name, QString &tv_class, QString &tv_fav, QString &tv_skip)
{
    ch_val.setNum(ui4_ch_val);
    name=ps_name;
    tv_class.setNum(ui4_class);
    tv_fav.setNum(ui4_isfav);
    tv_skip.setNum(ui4_isskip);

}

void    TCL_MTK_ATV_TV::Get_Data(QList<QString> *ch_data)
{
    QString tmp="";
    tmp.setNum(ui4_ch_val);
    ch_data->append(ps_name);
    tmp.setNum(ui4_class);
    ch_data->append(tmp);
    tmp.setNum(ui4_isfav);
    ch_data->append(tmp);
    tmp.setNum(ui4_isskip);
     ch_data->append(tmp);

}

void TCL_MTK_ATV_TV::Set_Data(QString &ch_val, QString &name, QString &tv_class, QString &tv_fav, QString &tv_skip)
{
    bool *ok;
    *ok=false;
    ps_name=name;
    ui4_ch_val=ch_val.toUInt(ok);
    Q_ASSERT(*ok==true);
    ui4_class=tv_class.toUInt(ok);
    Q_ASSERT(*ok==true);
    ui4_isfav=tv_fav.toUInt(ok);
    Q_ASSERT(*ok==true);
    ui4_isskip=tv_skip.toUInt(ok);
    Q_ASSERT(*ok==true);
}

void TCL_MTK_ATV_TV::Set_Data(QList<QString> &ch_data)
{
    Q_ASSERT(ch_data.size()==5);
    bool *ok;
    *ok=false;
    ui4_ch_val=ch_data.at(0).toUInt(ok);
    Q_ASSERT(*ok==true);
    ps_name=ch_data.at(1);
    ui4_class=ch_data.at(2).toUInt(ok);
    Q_ASSERT(*ok==true);
    ui4_isfav=ch_data.at(3).toUInt(ok);
    Q_ASSERT(*ok==true);
    ui4_isskip=ch_data.at(4).toUInt(ok);
    Q_ASSERT(*ok==true);
}

QString TCL_MTK_ATV_TV::Get_Item(int i)
{
    Q_ASSERT(i>=0&&i<5);
    QString tmp;
    switch(i)
    {
        case 1:
            tmp=ps_name;
            break;
        case 0:
            tmp.setNum(ui4_ch_val);
            break;
        case 2:
            tmp.setNum(ui4_class);
            break;
        case 3:
            tmp.setNum(ui4_isfav);
            break;
        case 4:
            tmp.setNum(ui4_isskip);
            break;
        default:
            tmp=" ";
            break;
      }
    return tmp;
}


int TCL_MTK_ATV_TV::Count_Item()
{
    return NUM_TV_ITEM;
}
